<template>
  <div style="height: 100%">
    <el-empty :description="errMsg" v-if="errMsg" />
    <component :is="current" v-else-if="current" />
  </div>
</template>
<script>
import auth from '@/plugins/auth'
import Quality from './courseCheck/constructionCourse'
import CIVIL_20230612 from './specialRule/civil/20230612'
import HARDCOVER_20230612 from './specialRule/hardcover/20230612'
import Delivery from './projectScore/versionDefault'
import Business from './businessScore/versionDefault'

const cpnMap = {
  Quality,
  CIVIL_20230612,
  HARDCOVER_20230612,
  Delivery,
  Business
}
export const cpnKeys = Object.keys(cpnMap)

export default {
  components: cpnMap,
  data() {
    return { errMsg: '加载中...', current: '' }
  },
  beforeRouteEnter(to, from, next) {
    // 更改标题
    const meta = to.meta || {}
    meta.title = to.query?.chkitemName || '检查项得分'
    next()
  },
  created() {
    const { isEnable, permCode, specialRule } = this.$route.query || {}
    if (!isEnable) return (this.errMsg = '检查项暂未启用')
    if (!permCode || !auth.hasPermi(`cq:eval:${permCode}:list`)) return (this.errMsg = '暂无权限访问')
    if (!specialRule) return (this.errMsg = '未配置特殊规则')
    if (!cpnKeys.includes(specialRule)) return (this.errMsg = '特殊规则配置有误，该组件不存在')

    this.current = specialRule
    this.errMsg = ''
  }
}
</script>
